#ifndef CHATMESSAGEDELEGATE_H
#define CHATMESSAGEDELEGATE_H

#include <QObject>
#include <QStyledItemDelegate>
#include <QPixmapCache>
#include <QPainter>
#include <QPainterPath>
#include <QTextDocument>

/**
 * 自定义消息绘制代理
 * 继承自QStyledItemDelegate，负责每个消息项的渲染
 */

class ChatMessageDelegate : public QStyledItemDelegate
{
    Q_OBJECT
public:

    explicit ChatMessageDelegate(QObject *parent = nullptr);

    // 绘制单个消息项
    void paint(QPainter *painter,const QStyleOptionViewItem &option,const QModelIndex &index) const override;

    // 返回项的理想尺寸
    QSize sizeHint(const QStyleOptionViewItem &option,const QModelIndex &index) const override;

private:

    // 绘制头像（带圆形裁剪）
    void drawAvatar(QPainter *painter, const QRect &rect, const QString &path) const;

    // 绘制文字气泡
    void drawTextBubble(QPainter *painter, QRect rect, const QString &text, bool isSend) const;
    // 图像消息绘制
    void drawImageBubble(QPainter *painter,QRect rect,const QString &imagePath) const;

};

#endif // CHATMESSAGEDELEGATE_H
